//
//  toupiaoxqViewController.m
//  hainingOASystem
//
//  Created by michael on 2017/12/12.
//  Copyright © 2017年 czd. All rights reserved.
//

#import "toupiaoxqViewController.h"
#import "toupiaoresultViewController.h"
@interface toupiaoxqViewController ()

@end

@implementation toupiaoxqViewController

- (void)viewDidLoad {
    [super viewDidLoad];
        self.title = @"投票页面";

        self.view.backgroundColor = [UIColor whiteColor];
       [self makeUI];
       [self requestdata];

    // Do any additional setup after loading the view.
}
-(void)requestdata{
// _id = @"7";
[MBProgressHUD showHUDAddedTo:self.view animated:YES];

 NSString *urlstring = [NSString stringWithFormat:@"%@%@",ktoupiaoxq,_id];
  [httpTool ZBPostNetDataWith:urlstring withDic:nil andSuccess:^(NSDictionary* dictionary){
  [MBProgressHUD hideHUDForView:self.view animated:YES];

  _dic = dictionary;

[_tableview reloadData];

    }
 andFailure:^{
  [MBProgressHUD hideHUDForView:self.view animated:YES];
 [self.view makeToast:@"服务器错误!"];

 }];

 }
#pragma mark -------- 界面
-(void)makeUI{
_tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight-kTopHeight-kTabBarHeight) style:UITableViewStylePlain];
_tableview.dataSource = self;
_tableview.delegate = self;
[self.view addSubview:_tableview];

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row ==0) {
 UITableViewCell* cell = [[UITableViewCell alloc]init];
 cell.selectionStyle = UITableViewCellSelectionStyleNone;
 UIImageView *image = [[UIImageView alloc]init];
NSString *url = [NSString stringWithFormat:@"%@%@",kip,_dic[@"imageUrl"]];
[image sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"加载"]];
image.frame = CGRectMake(10,10 , (KScreenWidth/2)-20, 200);
       [cell.contentView addSubview:image];
UILabel *namelabel = [[UILabel alloc]initWithFrame:CGRectMake(image.right+10, 10, 60, 20)];
namelabel.text =_dic[@"title"];
    [namelabel setFont:[UIFont boldSystemFontOfSize:13]];
       [cell.contentView addSubview:namelabel];
    
UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(KScreenWidth-100, 10, 50, 20)];
label2.text = @"票数:";
    [label2 setFont:[UIFont systemFontOfSize:12]];
       [cell.contentView addSubview:label2];
    
       UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(KScreenWidth-50, 10, 50, 20)];
      if (![_dic[@"number"] isEqual:[NSNull null]]){
label3.text = [NSString stringWithFormat:@"%@",_dic[@"number"]];
}
label3.textColor = [UIColor redColor];
    [label3 setFont:[UIFont systemFontOfSize:12]];
       [cell.contentView addSubview:label3];
    
 UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(image.right+10, namelabel.bottom  ,KScreenWidth-20-10-image.width, 100)];
 label4.numberOfLines = 0;
label4.text = @"民族:";
if (![_dic[@"intro"] isEqual:[NSNull null]]) {
label4.text = [NSString stringWithFormat:@"%@",_dic[@"intro"]];
}else{

        label4.text =@"" ;

}    [label4 setFont:[UIFont systemFontOfSize:12]];
       [cell.contentView addSubview:label4];
    
//     UILabel *label5 = [[UILabel alloc]initWithFrame:CGRectMake(label4.right, namelabel.bottom, 50, 20)];
//label5.text = @"汉族";
//    [label5 setFont:[UIFont systemFontOfSize:12]];
//       [cell.contentView addSubview:label5];
//
//        UILabel *label6 = [[UILabel alloc]initWithFrame:CGRectMake(image.right+10, label4.bottom  ,80, 20)];
//label6.text = @"出生年月日:";
//    [label6 setFont:[UIFont systemFontOfSize:12]];
//       [cell.contentView addSubview:label6];
//
//     UILabel *label7 = [[UILabel alloc]initWithFrame:CGRectMake(label6.right, label4.bottom, KScreenWidth-image.width-20-label6.width-10, 20)];
//label7.text = @"xxxx年xx月xx日";
//    [label7 setFont:[UIFont systemFontOfSize:12]];
//       [cell.contentView addSubview:label7];
//
//         UILabel *label8 = [[UILabel alloc]initWithFrame:CGRectMake(image.right+10, label4.bottom, KScreenWidth-image.width-20-10, 60)];
//    label8.numberOfLines = 0;
//label8.text = @"xxxx年xx月xx日";
//    [label8 setFont:[UIFont systemFontOfSize:12]];
//       [cell.contentView addSubview:label8];
   UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.frame = CGRectMake(image.right+10, image.bottom-90, label4.width, 40);
    [button1 setTitle:@"投票" forState:UIControlStateNormal];
        button1.titleLabel.font = [UIFont systemFontOfSize: 14.0];
    [button1 setImage:[UIImage imageNamed:@"爱心"] forState:UIControlStateNormal];
        [button1 layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:0];
button1.imageEdgeInsets = UIEdgeInsetsMake(10, 60, 10, 70);
[button1 setBackgroundColor:[UIColor blueColor]];
  [button1 addTarget:self action:@selector(action1) forControlEvents:UIControlEventTouchUpInside];
[cell .contentView addSubview:button1];

UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    button2.frame = CGRectMake(image.right+10, button1.bottom+10, label4.width, 40);
    [button2 setTitle:@"返回投票页" forState:UIControlStateNormal];
        button2.titleLabel.font = [UIFont systemFontOfSize: 14.0];
        [button2 addTarget:self action:@selector(action2) forControlEvents:UIControlEventTouchUpInside];
//    [button2 setImage:[UIImage imageNamed:@"爱心"] forState:UIControlStateNormal];
//        [button2 layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:0];
//button2.imageEdgeInsets = UIEdgeInsetsMake(15, 50, 15, 60);
[button2 setBackgroundColor:[UIColor blueColor]];
[cell .contentView addSubview:button2];
 
 return cell;
}else{
UITableViewCell* cell = [[UITableViewCell alloc]init];
 cell.selectionStyle = UITableViewCellSelectionStyleNone;
 UILabel *label1 = [[UILabel alloc]init];

label1.frame = CGRectMake(10, 10, 100, 20);
label1.text = @" 详情介绍 ";
label1.textColor = [UIColor blueColor];
     label1.font = [UIFont boldSystemFontOfSize:14];
    [cell .contentView addSubview:label1];
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, label1.bottom, KScreenWidth-10, 1)];
        view1.backgroundColor = [UIColor colorWithRed:213/225.0 green:213/225.0 blue:221/225.0 alpha:1];
    [cell .contentView addSubview:view1];
    UILabel *label2 = [[UILabel alloc]init];
    label2.numberOfLines = 0;
 NSString *string6 =_dic[@"content"];
//     label2.characterSpace=2;//字间距

label2.text =string6;
     label2.font = [UIFont systemFontOfSize:13];

        CGFloat titleSize6 = [OAToolBox sizebyText:string6 font:13 minsWidth:20];
        label2.text =string6;
label2.frame = CGRectMake(10, label1.bottom+10, KScreenWidth-20, titleSize6);
    [cell .contentView addSubview:label2];

 return cell;

}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == 0){

return 220;
}else
{  NSString *string6 =_dic[@"content"];

        CGFloat titleSize6 = [OAToolBox sizebyText:string6 font:13 minsWidth:20];
return titleSize6+40;


}


}
- (void)action1{
{

    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
NSString *toupiaoid = [NSString stringWithFormat:@"%@",_dic[@"id"]];
 NSString *urlstring = [NSString stringWithFormat:@"%@%@",ktoupiao,toupiaoid];
  [httpTool ZBPostNetDataWith:urlstring withDic:nil andSuccess:^(NSDictionary* dictionary){
  [MBProgressHUD hideHUDForView:self.view animated:YES];

 if ([[NSString stringWithFormat:@"%@",dictionary[@"success"]]isEqualToString:@"true"]) {
           [self .view makeToast:dictionary[@"msg"]];
 
     
}else{
NSString *string = dictionary[@"msg"];
           [self .view makeToast:string ];

}

    }
 andFailure:^{
  [MBProgressHUD hideHUDForView:self.view animated:YES];
 [self.view makeToast:@"服务器错误!"];

 }];


}



}
- (void)action2{
toupiaoresultViewController *vc = [[toupiaoresultViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
